﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Vowei.Core;
using System.Diagnostics;

namespace Vowei.Data.Converters
{
    public abstract class FormatConverter
    {
        public ITranslator Translator { get; set; }
        //private ITranslator _translator = null;
        //public ITranslator Translator 
        //{
        //    get 
        //    {
        //        if (_translator == null)
        //        {
        //            Trace.TraceWarning("没有给FormatConverter指定转换使用的区域设置，使用默认的区域设置！");
        //            _translator = DefaultTranslator;
        //        }

        //        return _translator; 
        //    }
        //    set { _translator = value; }
        //}

        protected FormatConverter()
            : this(DefaultTranslator)
        {
        }

        protected FormatConverter(ITranslator translator)
        {
            Translator = translator;
        }

        protected static ITranslator _defaultTranslator;
        protected static ITranslator DefaultTranslator
        {
            get
            {
                if (_defaultTranslator == null)
                {
                    _defaultTranslator = new Translator(CultureInfo.CurrentCulture);
                }

                return _defaultTranslator;
            }
        }

        public abstract bool CanConvert(object stream);

        public abstract object ConvertFrom(object from);

        public abstract void ConvertTo(object from, object to);
    }
}
